<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script src="{{ getAssets }}js/jquery.table2excel.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : '{{ urlfor "GspController.Entryreturn"}}'
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
            var queryParams = checkQueryTableData(aoData);
            var form = $('.query-form').serializeArray();
            $.each(form, function(i, value){
                queryParams[value.name] = value.value;
            });
            $.post(sSource, JSON.stringify(queryParams),function(resp) {
                isLoading = true;
                fnCallback(resp);
            },'json')
		}
        ,order: []
		,columns: [
			{"bSortable": false, render:function(data, type, full, meta) {
                return productTypeidName(full.Products.TypeId);
			}}
			,{"bSortable": false, render:function(data, type, full, meta) {
                return full.Products.Suppliers.Name;
			}}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                 return full.Products.BrandName;
            }}
			,{"bSortable": false,render:function(data, type, full, meta) {
				return full.Products.Name;
			}}
            ,{"bSortable": false,render:function(data, type, full, meta) {
                    //return timetransDate(full.Entry.CreatedAt);
                 return full.Products.ColourNumber
            }}
            ,{"bSortable": false,render:function(data, type, full, meta) {
                    return full.Products.Spec;
             }}
            ,{"bSortable": false,render:function(data, type, full, meta) {
                    return full.Products.RegistrationId
            }}
            ,{"bSortable": false,render:function(data, type, full, meta) {
                    return full.Products.CastAway
            }}
			,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Products.ShelfLife
			}}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Products.Unit;
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.StorageNum;
                }}
            ,{"bSortable": false,render:function(data, type, full, meta) {
                    return timetransDate(full.CreatedAt);
                }}
            ,{"bSortable": false,render:function(data, type, full, meta) {
                    return full.PurchaseUpNo;
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Snd.sph;
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Snd.cyl;
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Acceptance.lot_number;
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return timetransDate(full.Acceptance.manufacture_date);
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return timetransDate(full.Acceptance.expiry_date);
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Products.Suppliers.GspCertificate;
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Products.Suppliers.GspCertificateEnddate;
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Products.Manufacturer;
                }}
		]
		,"lengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示
        ,'bLengthChange': true
	});
	
	$("#query-submit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});
    var isLoading = false;
    $('#download').bind("click", function(){
        if(isLoading) {
            $("#dataTables").table2excel({

                exclude: ".noExl",

                name: "导出GSP采退记录",

                filename: "GSP采退记录",

                fileext: ".xls",

                exclude_img: false,

                exclude_links: false,

                exclude_inputs: false
            });
        } else {
            $("#searchsubmit").click();
            layer.msg("还没加载结束请耐心等待一下！");return false;
        }
        return false;
    });
</script>